package com.yongdin.minimalism.wifi;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yongdin.minimalism.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: WiFiInfoAdapter
 * @Description: java类作用描述
 * @Author: luweiming
 * @CreateDate: 2020/3/24 15:57
 * @Version: 1.0
 */
class WiFiInfoAdapter extends BaseAdapter {
    private Context mContext;
    private List<WifiInfo> wifiInfos=new ArrayList<>();
    public WiFiInfoAdapter(Context context, ArrayList<WifiInfo> wifiArray) {
        this.mContext=context;
        this.wifiInfos=wifiArray;
    }

    @Override
    public int getCount() {
        return null==wifiInfos?0:wifiInfos.size();
    }

    @Override
    public Object getItem(int i) {
        return wifiInfos.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        View contentView= LayoutInflater.from(mContext).inflate(R.layout.item_wifi_list_layout,null,false);
        TextView tvName= (TextView) contentView.findViewById(R.id.tv_name);
        tvName.setText(wifiInfos.get(i).getSSID());
        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null!=listener)
                    listener.onItemClick(i);
            }
        });
        return contentView;
    }
    public void setListener(ClickListener l){
        listener=l;
    }
    private ClickListener listener;
    public interface ClickListener{
        void onItemClick(int position);
    }
}
